//
//  ShenPiXiaoXiTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/1.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ShenPiXiaoXiTableViewCell.h"
#import "NSDate+Helper.h"
@implementation ShenPiXiaoXiTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    
    _backImage.image = [self getResizableImage:LocalImagePath(@"chat_from_bg_normal")];

    
}
- (UIImage *)getResizableImage:(UIImage *)image{
    return [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.5, image.size.width * 0.5, image.size.height * 0.5, image.size.width * 0.5)];
}
- (void)setModel:(AllModel *)model{
    _model = model;
    NSDictionary *dataDic = model.modelInfoDictionary;
    
    _timeLabel.text = [self huoQuShiJian:GetHandleString(dataDic, @"createTime")];
    _redView.hidden = [GetHandleString(dataDic, @"isRead") boolValue];
    if(model.isNeedShow){
        _riQiLabel.text = GetHandleString(dataDic, @"createTime");
        _topSpace.constant = 53;
        [_chaKanButton setBackgroundColor:rgba(220, 233, 255, 1)];
        [_chaKanButton setTitleColor:rgba(40, 120, 255, 1) forState:UIControlStateNormal];
        _lineView.backgroundColor = rgba(40, 120, 255, 1);
        _headImage.image = LocalImagePath(@"审批消息");
        
        if([GetHandleString(dataDic, @"type") intValue] == 25){
            _titleLabel.text = [NSString stringWithFormat:@"%@提交了《%@》",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
            _shenPiShiYouRemindLabel.text = @"";
            _shiYouLabel.text = @"";
            _topSpace.constant = 0;
        }else if([GetHandleString(dataDic, @"type") intValue] == 6){
            _titleLabel.text = [NSString stringWithFormat:@"%@拒绝了您的《%@》",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
            _shenPiShiYouRemindLabel.text = @"拒绝理由";
            _shiYouLabel.text = GetHandleString(dataDic, @"content");
            _topSpace.constant = 12;
        }else if([GetHandleString(dataDic, @"type") intValue] == 7){
            _titleLabel.text = [NSString stringWithFormat:@"%@通过了您的《%@》",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
            _shenPiShiYouRemindLabel.text = @"";
            _shiYouLabel.text = @"";
            _topSpace.constant = 0;
        }
    }else{
        
        _shenPiShiYouRemindLabel.text = @"";
        _shiYouLabel.text = @"";
        _topSpace.constant = 0;
        
        if([GetHandleString(dataDic, @"type") intValue] == 23){
            _titleLabel.text = [NSString stringWithFormat:@"%@将您添加为客户《%@》的成员",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
        }else if([GetHandleString(dataDic, @"type") intValue] == 32){
            _titleLabel.text = [NSString stringWithFormat:@"%@将您移除客户《%@》的团队",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
        }else if([GetHandleString(dataDic, @"type") intValue] ==29){
            _titleLabel.text = [NSString stringWithFormat:@"%@退出了您的《%@》的团队",GetHandleString(dataDic, @"realname"),GetHandleString(dataDic, @"title")];
        }
        
        if([GetHandleString(dataDic, @"type") intValue] == 23 || [GetHandleString(dataDic, @"type") intValue] == 32 || [GetHandleString(dataDic, @"type") intValue] == 29){
            _faQiRiQiRemindLabel.text = @"客户姓名";
            _riQiLabel.text = GetHandleString(dataDic, @"title");
       
            _topSpace.constant = 12;
            [_chaKanButton setBackgroundColor:rgba(255, 245, 229, 1)];
            [_chaKanButton setTitleColor:rgba(255, 180, 68, 1) forState:UIControlStateNormal];
            _lineView.backgroundColor = rgba(255, 180, 68, 1);
            _chaKanButton.hidden = NO;
            _chaKanTopSpace.constant = 16;
            _chaKanButtonHeight.constant = 32;
        }else{
            _titleLabel.text = @"您有一条客户消息，请前往电脑端查看";
            
            _faQiRiQiRemindLabel.text = @"";
            _riQiLabel.text = @"";
       
            _topSpace.constant = 0;
            _chaKanButton.hidden = YES;
            _chaKanTopSpace.constant = -12;
            _chaKanButtonHeight.constant = 0;
            [_chaKanButton setBackgroundColor:rgba(255, 245, 229, 1)];
            [_chaKanButton setTitleColor:rgba(255, 180, 68, 1) forState:UIControlStateNormal];
            _lineView.backgroundColor = rgba(255, 180, 68, 1);
        }
      
        _headImage.image = LocalImagePath(@"客户消息");
    }
    [self setupAutoHeightWithBottomView:_backView bottomMargin:8];
}

- (NSString *)huoQuShiJian:(NSString *)time{
    NSString *result = time;
    double timeRes = [[NSDate date] hoursLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]];
    if(timeRes > 0 && timeRes < 1){
        if([[NSDate date] minutesLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]] < 1){
            result = @"1分钟前";
        }else{
            result = [NSString stringWithFormat:@"%.0f分钟前",[[NSDate date] minutesLaterThan:[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"]]];
        }
    }else if ([[NSDate dateFromString:time withFormat:@"yyyy-MM-dd HH:mm:ss"] isToday]){
        result = [NSDate dateStringFromString:time format:@"yyyy-MM-dd HH:mm:ss" toFormat:@"HH:mm"];
    }else{
        result = [NSDate dateStringFromString:time format:@"yyyy-MM-dd HH:mm:ss" toFormat:@"yyyy-MM-dd HH:mm"];
    }
    return result;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
